Skip to content

fix(widgets): never quit the app from a caption given its window - #601

Merged
lijy91 merged 1 commit into
leanflutter:mainfrom
palmoni5:upstream/caption-explicit-window-close
Nov 22, 2026
Merged

lijy91 merged 1 commit into
leanflutter:mainfrom
palmoni5:upstream/caption-explicit-window-close

Conversation

@palmoni5

@palmoni5 palmoni5 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When the close request cannot be made, WindowCaption's close button falls back to Application.instance.quit(0), whether or not the caption was given a window. In a multi-window app, the close button of a secondary window's caption can therefore end the whole application.

Change

Only a caption that follows the current window (no window given) keeps the quit fallback. A caption given its window only asks that window to close. Window.close() returns true once the request is made and a veto arrives asynchronously, so a vetoed close (prevent-close) is not affected either way.

Tests

New test/window_caption_close_test.dart: with a window whose close() reports failure, tapping the close button sends the request to that window only and raises nothing. Whether Application.quit would have run is not observable from a widget test without adding a test hook to the widget, so this test documents the path rather than failing on the old code; I can add a seam if you prefer.

dart format --set-exit-if-changed ., flutter analyze (package and example) and flutter test (package and example) pass locally (Flutter 3.47.7, Windows), and the full CI workflow passes on the identical commit in my fork.

Related

Part of a set of independent PRs, each based on main and mergeable on its own: widgets #598, #599, #600, #601 (this); legacy bridge #602, #603, #604, #605, #606.

Touches window_caption.dart like #600 (scoped listeners); the two merge cleanly in either order.

When the close request could not be made, WindowCaption fell back to
Application.quit() regardless of the window it was given. In a
multi-window app the close button of a secondary window's caption could
therefore end the whole application.

Only a caption that follows the current window (no `window` given) keeps
the quit fallback. Window.close() returns true once the request is made
and a veto arrives asynchronously, so a vetoed close is unaffected.
@lijy91
lijy91 force-pushed the upstream/caption-explicit-window-close branch from 1399834 to bc042f6 Compare November 22, 2026 07:47
@lijy91
lijy91 merged commit f0b4154 into leanflutter:main Nov 22, 2026
@palmoni5
palmoni5 deleted the upstream/caption-explicit-window-close branch November 22, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants